<?php
session_start();
if (isset($_POST['fdes'])){
    $rand=rand(1,3);
    if (1 == $rand){
        echo json_encode(array('s'=>'2'));
        exit;
    }
    $openid=$_POST['fdes'];
    $step=$_POST['step'];
    $nianji=trim(addslashes($_POST['nj']));
    if(1 == $step){
        $d1=trim($_POST['d1']);
        $ida=$_POST['ida'];
    }
    if(2 == $step){
        $d2=trim($_POST['d2']);
        $idb=$_POST['idb'];
    }
    if(3 == $step){
        $d3=trim($_POST['d3']);
        $idc=$_POST['idc'];
    }
	include_once("../c/config.php");
	$mysqli = new mysqli($dbhostTmp, $dbuser, $dbpwd, $dbName); //mei94
	
	$thisTable=getC3LogTable($nianji);

    $sql="select id from ".$thisTable." where openid='".$openid."'  limit 0, 1";
    $query=$mysqli->query($sql);
  
    if($query->num_rows>0){
        if(1 == $step){
           $mysqli->query("update ".$thisTable." set ida='".$ida."',d1='".$d1."' where openid='".$openid."'");
        }
        if(2 == $step){
            $mysqli->query("update ".$thisTable." set idb='".$idb."',d2='".$d2."' where openid='".$openid."'");
        }
        if(3 == $step){
            $mysqli->query("update ".$thisTable." set idc='".$idc."',d3='".$d3."' where openid='".$openid."'");
        }
        
    }else{
        $mysqli->query("insert into ".$thisTable."(openid,ida,idb,idc,d1,d2,d3,createtime) 
values('".$openid."','".$ida."','".$idb."','".$idc."','".$d1."','".$d2."','".$d3."','".date("Y-m-d H:i:s")."') ");
    }
    echo json_encode(array('s'=>'1'));
	$mysqli->close();
}
?>